﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EzDesk.EzAppApi.Web.Utility.Attributes;
using EzDesk.EzAppApi.Utility.Models;
using System.Text;
using EzDesk.Project.Model;
using EzDesk.Project.Service;
using EzDesk.EzAppApi.Web.Utility.Controllers;
using EzDesk.EzAppApi.Utility;

namespace EzDesk.Project.MobileWeb.Controllers
{
    public class ProjectController : EzAppController
    {
        private IProjectService _projectService;

        public ProjectController(IEzApiClient apiClient, IProjectService projectService)
        {
            this._apiClient = apiClient;
            this._projectService = projectService;
        }

        //todo: DI重构
        public ProjectController()
            : this(new EzApiClient(), new ProjectService())
        { }

        #region [ Tasks ]
        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult Task()
        {
            AppTaskCollection taskCollection = new AppTaskCollection();

            // 把现在系统里的项目全部取出来
            var currentProjectList = _projectService.GetProjetList(isClosed : false, orderBy : "CreateOn");

            foreach (var project in currentProjectList)
            {
                taskCollection.AddTask(
                    project.ProjectName,
                    "查看[" + project.ProjectName + "]项目详细信息",
                    string.Format("/project/projectDetail?projectId={0}", project.Id.ToString())
                    );
            }

            taskCollection.AddTask("项目总览", "打开所有项目列表", "/project/projectList");

            taskCollection.AddTask("我的工作日志", "查看我的工作日志和计划", "/project/myWorkItem");
            taskCollection.AddTask("公司工作日志", "查看大家的工作日志和计划", "/project/workItemList");
                

            return Task(taskCollection);
        }

        #endregion

        #region [ Pages ]

        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult ProjectList()
        {
            return View();
        }

        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult ProjectDetail()
        {
            return View();
        }

        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult PlaneTask()
        {
            return View();
        }


        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult TaskDetail()
        {
            return View();
        }

        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult WorkItemDetail()
        {
            return View();
        }

        [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult MyWorkItem()
        {
            return View();
        }

                [HttpGet]
        [EzDeskAppSessionAuthorize]
        public ActionResult WorkItemList()
        {
            return View();
        }


        #endregion


    }
}
